package cn.itcast.mq.message.listener;

import cn.itcast.util.SmsDemo;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.core.Message;

import java.util.Map;

public class MessageListener implements org.springframework.amqp.core.MessageListener {
    @Override
    public void onMessage(Message message) {
        byte[] body = message.getBody();
        ObjectMapper objectMapper = new ObjectMapper();

        try {
            Map<String , String> map = objectMapper.readValue(body,Map.class);
            String telephone = map.get("telephone");
            String smsCode = map.get("smsCode");
            System.out.println("=========================");
            System.out.println("=========================");
            System.out.println("=========================");
            System.out.println(telephone);
            System.out.println(smsCode);
            System.out.println("=========================");
            System.out.println("=========================");
            System.out.println("=========================");
            //SmsDemo.sendSms(telephone,smsCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
